package com.example.controller;


import com.example.annotation.AuthConfig;
import com.example.annotation.RepeatSubmit;
import com.example.entity.Article;
import com.example.service.IArticleService;
import com.example.utils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王鹤蒲
 * @since 2023-08-29
 */
@Api(tags = "文章信息API",description="提供文章信息相关的 REST API")
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private IArticleService articleService;


    @RequestMapping(value="/save",method= RequestMethod.POST)
    @RepeatSubmit(lockTime = 5)
    @ResponseBody
    public R saveArticle(@RequestBody Article article){
       return articleService.saveArticle(article);
    }

    @RequestMapping(value="/edit/{id}",method= RequestMethod.POST)
    @RepeatSubmit(lockTime = 5)
    @ResponseBody
    public R editArticle(@PathVariable("id") Integer id,@RequestBody Article article) {
       return articleService.updateArticle(id,article);
    }


    @RequestMapping(value="/selectAll",method= RequestMethod.GET)
    @ResponseBody
    @AuthConfig
    public R selectAll(@RequestParam(defaultValue = "") String title, @RequestParam int currentPage,@RequestParam int pageSize) {
        return articleService.selectAll(title,currentPage,pageSize);
    }


    @RequestMapping(value="/delete/{id}",method= RequestMethod.DELETE)
    @ResponseBody
    public R deleteById(@PathVariable("id")Integer id) {
        return articleService.deleteById(id);
    }

    @RequestMapping(value="/deleteBatch",method= RequestMethod.POST)
    @ResponseBody
    public R deleteByIds(@RequestBody Integer[] ids) {
         return articleService.deleteByIds(ids);
    }

    @RequestMapping(value="/{id}",method=RequestMethod.GET)
    @ResponseBody
    @AuthConfig
    public R queryArticleDetail(@PathVariable("id") Integer id) {
        return articleService.queryArticleDetail(id);
    }

}

